#pragma once

#ifdef _WIN32
#include <Winsock2.h>
#elif _UNIX
#include <arpa/inet.h>
#endif 

#include <memory>
#include <iostream>

constexpr auto MSG_ID_LEN = 2;
constexpr auto MSG_DATA_LEN = 8;
constexpr auto MSG_HEADER_LEN = MSG_ID_LEN + MSG_DATA_LEN;
constexpr auto MSG_MAX_DATA_LEN = 4096;


enum class MsgType {
	TYPE_TEXT = 1,
	TYPE_FILE // 文件类型

};

enum class FileType {
	TYPE_ERROR = 0,
	TYPE_GET_FILE_TREE,	// 获取文件树
	TYPE_GET_FILE_TREE_RESPONSE,	// 获取文件树
	TYPE_GET_FILE_TREE_FINISH,	// 获取文件树
	// 上传与下载
	TYPE_FILE_UPLOAD,
	TYPE_FILE_DOWNLOAD,
	TYPE_FILE_UPLOAD_RESPONSE,
	TYPE_FILE_DOWNLOAD_RESPONSE,
	TYPE_FILE_UPLOAD_STOP,
	TYPE_FILE_DOWNLOAD_STOP,
	TYPE_FILE_UPLOAD_RESPONSE_FINISH,
	TYPE_FILE_DOWNLOAD_RESPONSE_FINISH,
	// 断点续传
	TYPE_FILE_RETRY_UPLOAD,
	TYPE_FILE_RETRY_DOWNLOAD
};

enum class FileErrorType {
	UNKNOWN_ERROR = 0,
	FILE_NO_EXISTS,
	FILE_OPEN_FAIL,
	GET_FILE_TREE_ERROR
};

struct MsgNode {
	MsgNode(uint64_t maxLen);
	virtual ~MsgNode();
	void clear();

	uint64_t totalLen_;
	uint64_t curLen_;
	char* data_;
};

struct SendNode :public MsgNode{
	SendNode(char* msg,short msgId, int64_t maxLen);
	short msgId_;
};

struct RecvNode:public MsgNode {
	RecvNode(short msgId, int maxLen);
	short msgId_;
};

